package com.huangmingrui.controller;

import com.huangmingrui.dao.HmrDao;
import com.huangmingrui.pojo.Hmr;
import com.util.BaseDao;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("stu")
public class HmrController {
//    @Autowired
//    HmrDao HmrDao;

    @RequestMapping("query")
    public String query(Model model){
        SqlSession session = BaseDao.getSession();
        HmrDao stuMpapper = session.getMapper(HmrDao.class);
        List<Hmr> list = stuMpapper.query();
//          List<Hmr> list = HmrDao.query();
        session.commit();
        session.close();
        model.addAttribute("list",list);
        return "list";
    }

    @RequestMapping("add")
    public String add(){
        return "add";
    }

    @RequestMapping("save")
    public String save(Hmr hmr){
        SqlSession session = BaseDao.getSession();
        HmrDao stuMpapper = session.getMapper(HmrDao.class);
        int a =stuMpapper.save(hmr);
//          int a  = HmrDao.save(hmr);
        session.commit();
        session.close();
        return "redirect: query";
    }
    @RequestMapping("del")
    public String del(Integer id){
        SqlSession session = BaseDao.getSession();
        HmrDao stuMpapper = session.getMapper(HmrDao.class);
        int a =stuMpapper.del(id);
//          int a = HmrDao.del(id);
        session.commit();
        session.close();
        return "redirect: query";
    }
    @RequestMapping("index")
    public String index(){
        return "index";
    }
}
